package com.zzty.txj.serviceImpl;

import com.alibaba.fastjson.JSONObject;
import com.zzty.txj.dao.RecordMapper;
import com.zzty.txj.entity.DoDaily;
import com.zzty.txj.entity.User;
import com.zzty.txj.service.RecordService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

import static com.zzty.txj.util.HttpUtil.httpGet;

@Service
public class RecordServiceImpl implements RecordService {
    private static final org.slf4j.Logger logger = LoggerFactory.getLogger(RecordServiceImpl.class);
    @Autowired
    RecordMapper recordMapper;
    @Override
    public List<DoDaily> getDoDaily(DoDaily doDaily) {
       List<DoDaily>doDailys = recordMapper.getDoDaily(doDaily);
        return doDailys;
    }


    @Value("${url.user.getUserByOpenId}")
    String url;
    @Override
    public Integer getUserId(String openId) {
        String us=null;
        User user=new User();
        try {
            us=httpGet(url+openId);

            // us=HttpUtil.httpGet(url+user.getOpenId());
            user=JSONObject.parseObject(us,User.class);
logger.info("RecordServiceImpluser"+user);

        } catch (Exception e) {
            e.printStackTrace();
        }
        Integer id = user.getId();
        return id;
    }



    @Override
    public String getDailyName(Integer id) {
        String name = recordMapper.getDailyName(id);
        return name;
    }

    @Override

    public List<DoDaily> getDaily() {
        List<DoDaily>doDailys = new ArrayList<>();
        if(doDailys==null){
            return  null;
        }else {
            doDailys   =  recordMapper.getDaily();
        }

        return doDailys;
    }

    @Override
    public List<DoDaily> getWeek(User user) {
        List<DoDaily>doDailys = recordMapper.getWeek(user);
        return doDailys;
    }

    @Override
    public List<DoDaily> getMonth(User user) {
        List<DoDaily>doDailys = recordMapper.getMonth(user);
        return doDailys;
    }
}
